package org.dromara.comm_lhz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.dromara.comm_lhz.entity.AsVolunteerInfoEntity;
import org.dromara.comm_lhz.mapper.AsVolunteerInfoHMapper;
import org.dromara.comm_lhz.service.AsVolunteerInfoHService;
import org.dromara.common.core.utils.StringUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class AsVolunteerInfoHHServiceImpl extends ServiceImpl<AsVolunteerInfoHMapper, AsVolunteerInfoEntity> implements AsVolunteerInfoHService {

    private final AsVolunteerInfoHMapper asVolunteerInfoHMapper;

    /**
     * 查询志愿者数据
     * @param asVolunteerInfoEntity 志愿者信息实体，用于构建查询条件
     * @param pageable 分页参数，指定页码和每页条数
     * @return 分页的志愿者信息列表
     */
    @Override
    public Page<AsVolunteerInfoEntity> selVolunteerInfo(AsVolunteerInfoEntity asVolunteerInfoEntity, Pageable pageable) {
        // 构建模糊名字查询条件
        LambdaQueryWrapper<AsVolunteerInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(asVolunteerInfoEntity.getName()), AsVolunteerInfoEntity::getName, asVolunteerInfoEntity.getName());
        // 添加状态为1的过滤条件
        queryWrapper.eq(AsVolunteerInfoEntity::getState, 1);
        // 分页
        Page<AsVolunteerInfoEntity> page = new Page<>(pageable.getPageNumber(),pageable.getPageSize());

        return asVolunteerInfoHMapper.selectPage(page, queryWrapper);
    }

    /**
     * 根据状态获取志愿者申请列表
     * 此方法通过状态筛选，从数据库中检索符合条件的志愿者信息
     * @param asVolunteerInfoEntity 志愿者信息实体，用于构建查询条件
     * @param pageable 分页参数，指定页码和每页条数
     * @return 返回符合条件的志愿者信息列表，以分页形式展示
     */
    @Override
    public Page<AsVolunteerInfoEntity> getVolunteerInfoByState(AsVolunteerInfoEntity asVolunteerInfoEntity, Pageable pageable) {
        // 创建查询构造器，用于指定查询条件
        LambdaQueryWrapper<AsVolunteerInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(asVolunteerInfoEntity.getName()), AsVolunteerInfoEntity::getName, asVolunteerInfoEntity.getName());

        // 设置查询条件，筛选志愿者状态匹配的记录
        queryWrapper.eq(AsVolunteerInfoEntity::getState, 0);

        Page<AsVolunteerInfoEntity> page = new Page<>(pageable.getPageNumber(), pageable.getPageSize());
        // 执行查询并返回分页显示的志愿者信息列表
        return asVolunteerInfoHMapper.selectPage(page, queryWrapper);
    }

}
